<?php
defined('_JEXEC') or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class DanhMucViewDetail extends JView
{
	function display($tpl = null)
	{
		global $mainframe;

		if($this->getLayout() == 'default') {
			$this->_display($tpl);
			return;
		}
		parent::display($tpl);
	}
	function _display($tpl)
	{
		global $mainframe, $option;
		$db		=& JFactory::getDBO();
		$uri 	=& JFactory::getURI();
		$model	=& $this->getModel();

		$lists = array();
		$detail	=& $this->get('data');		

		//////////////////////////////////////////////////////
		$temp1 = array ('0'=>array('id'=>0,'title'=>'Danh Mục Gốc'));
		$temp2 = $this->getListCategory('0','');
		if($temp2)
			$sel = @array_merge($temp1,$temp2);
		else
			$sel=$temp1;
		$lists['sel']=JHTML::_('select.genericList',$sel,'parent_id', 'class="inputbox"'.'','id','title',$detail->parent_id);
		//////////////////////////////////////////////////////
		$position = array('0'=>array('value'=>'1','text'=>'Trái'),
							'1'=>array('value'=>'2','text'=>'Phải')
				);
		$lists['position'] = JHTML::_('select.genericList',$position,'position','class="inputbox" '.'','value','text',$detail->position);
		// build list of categories
		$lists['parentid'] 			= JHTML::_('list.category',  'parent_id', $option, $detail->parent_id );
		// build the html select list
		$lists['published'] 		= JHTML::_('select.booleanlist',  'published', 'class="inputbox"', $detail->published );

		$this->assignRef('lists',		$lists);
		$this->assignRef('detail',		$detail);

		parent::display($tpl);
	}
	private function getListCategory($id,$text){ 
		global $category;
		$db =&JFactory::getDBO();
		$query = 'select * from #__category where parent_id = '.$id.' ORDER BY ordering ';
		$db->setQuery($query);
		$rows = $db->loadAssocList();
		foreach($rows as $key=>$value){
			$value['title'] = substr($text.'|_ '.$value['title'],2);
			$category[] = $value;
			$this->getListCategory($value['id'],$text.'. &nbsp;&nbsp;&nbsp;&nbsp;');
		} 
		return $category;
	}
}